import 'package:dali_ng_pera/page/widget/dnp_lifecycle_widget.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import '../widget/dnp_classic_header.dart';
import 'dnp_home_tab_controller.dart';
import 'mixin/dnp_home_big_card_mixin.dart';
import 'mixin/dnp_home_heard_mixin.dart';
import 'mixin/dnp_home_small_card_mixin.dart';

class DnpHomeTabPage extends StatefulWidget {
  const DnpHomeTabPage({super.key});

  @override
  State<DnpHomeTabPage> createState() => _DnpHomeTabPageState();
}

class _DnpHomeTabPageState extends State<DnpHomeTabPage>
    with DnpHomeBigCardMixin, DnpHomeSmallCardMixin, DnpHomeHeardMixin {
  final controller = Get.put(DnpHomeTabController());

  // @override
  // void initState() {
  //   super.initState();
  //   controller.onRequestData(showLoading: true);
  // }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: DnpLifecycleWidget(
          ctx: context,
          subWidget: Stack(
            children: [
              Obx(() => Container(
                      decoration: BoxDecoration(
                    image: DecorationImage(
                      image: AssetImage(controller.largeCard.value
                          ? 'assets/images/ic_big_main_bg.webp'
                          : 'assets/images/ic_default_main_bg.webp'),
                      fit: BoxFit.fill,
                    ),
                  ))),
              Padding(
                padding: EdgeInsets.only(
                    left: 16.0,
                    right: 16.0,
                    top: MediaQuery.of(context).padding.top),
                child: Obx(() => SmartRefresher(
                      header: DnpClassicHeader(),
                      controller: controller.refreshController,
                      onRefresh: controller.onRequestData,
                      child: controller.largeCard.value
                          ? buildBigCard(
                              context, controller.homeDataModel.value)
                          : buildSmallCard(context,controller.homeDataModel.value),
                    )),
              ),
            ],
          ),
          show: () {
            controller.onRequestData(showLoading: true);
          }),
    );
  }
}
